Computers generally employ several types of memory for data storage. Many computers have at least registers in a central processing unit ("CPU") or microprocessor, and a main memory for data storage. Register storage generally provides the fastest access time for storage and retrieval of data. However, because of cost and size considerations, computers generally have a limited number of registers which store a relatively small amount of data. By contrast, a computer's main memory generally stores a relatively large amount of data, but provides much slower access times. Typical computers may also have an intermediate or cache memory which provides a quicker average access time to data stored in main memory, and mass storage devices which provide non-volatile data storage.
Because register storage is typically very limited in amount, most of the data for operations in a program is stored in the main memory of a computer. The data is moved from main memory to register storage as required during program execution. Because of the slow access time of main memory, execution of program operations for which data must be moved to or from main memory is generally slower than operations using data already in register storage. Typically, the computer is put into a "wait state," delaying the execution of such operations, while the data access to main memory is completed. Program operations using data already in register storage need not be delayed for a memory access, and generally execute more quickly. Accordingly, programmers desiring to increase the speed of program execution generally arrange a program's operations to minimize transfers of data between the main memory and register storage.
In a typical computer, the CPU includes both general purpose and special purpose registers. General purpose registers are used for storing operands, or pointers to operands in memory which are used for operations executed on the CPU. Special purpose registers generally store data related to limited purposes, such as for storing data relating to control, exceptions, memory management, and the like. For example, in many computers, an instruction register is provided for the limited purpose of storing a pointer to the currently executing instruction. Such special purpose registers generally are not available for general purpose use (i.e. storage of operands and results of operations).
Some computers, such as personal computers using the 80386, 80486 and Pentium.TM. microprocessors available from Intel Corporation (hereafter "Intel microprocessors"), provide a special purpose register herein referred to as a stack pointer register (the "SP" or "ESP" register in the Intel microprocessors). The stack pointer register is used to implement a type of data storage generally known as a stack. In computer systems which use the Intel microprocessors, the stack comprises a set of consecutive memory locations in main memory which is referred to as a stack segment. (Data, referred to as a segment selector, which identifies the stack segment is contained in a separate stack segment register in the Intel microprocessors.) The stack pointer register contains a pointer (the "stack pointer") to a location in the stack segment of the last data "pushed" onto the stack. The Intel microprocessors respond to an instruction set which includes two stack operations, generally known as push and pop. The push operation stores additional data in a sequential order onto the stack, while the pop operation removes data from the stack in last-in-first-out ("LIFO") order.
In the Intel microprocessors, the stack is used to store a return address when switching execution between programs, such as when an interrupt occurs. Specifically, when the microprocessor receives an interrupt, the address of the instruction currently being executed is pushed onto the stack. The starting address of an interrupt handler (a program for servicing an interrupt) is then loaded into the instruction register from a predetermined location in main memory, and the microprocessor begins executing the interrupt handler. After completing execution of the interrupt handler, the microprocessor returns to the previously executing program by popping the address of the instruction where program execution left off from the stack, and loading that address into the instruction register.
In the Intel microprocessors, an interrupt can occur at any time. Accordingly, if data other than the stack pointer (i.e. the address of the last data pushed onto the stack) is stored into the stack pointer register, a subsequent interrupt can cause the current instruction address to be stored at other than the next sequential location in the stack segment, possibly overwriting data previously stored in the stack. (Haphazardly overwriting data in a stack in this manner is herein referred to as "corrupting" the stack.) For this reason, the stack pointer register has not previously been used for general purpose storage of operands and results.